Skip to content

ProcGen & Scene Static Upload Memory Optimizations#1061

Open
RuffledPlume wants to merge 110 commits into
117HD:masterfrom
RuffledPlume:ProceduralGeneratorAllocFree
Open

ProcGen & Scene Static Upload Memory Optimizations#1061
RuffledPlume wants to merge 110 commits into
117HD:masterfrom
RuffledPlume:ProceduralGeneratorAllocFree

Conversation

@RuffledPlume
Copy link
Copy Markdown
Contributor

@RuffledPlume RuffledPlume commented Apr 24, 2026

Main:

DEBUG r.h.s.ProceduralGenerator      - procedural data generation took 238ms to complete
DEBUG r.h.s.ProceduralGenerator      - -- calculateTerrainNormals: 33ms (104 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateTerrainData: 128ms  (57 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateUnderwaterTerrain: 77ms  (423 MB)
image

PR:

DEBUG r.h.s.ProceduralGenerator      - procedural data generation took 44ms to complete
DEBUG r.h.s.ProceduralGenerator      - -- calculateMainTileOverrides: 8ms (19 MB)
DEBUG r.h.s.ProceduralGenerator      - -- calculateTerrainNormals: 10ms (27 MB) 
DEBUG r.h.s.ProceduralGenerator      - -- generateTerrainData: 18ms (14 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateUnderwaterTerrain: 8ms (37 MB)
image

Key Changes

Introduces Primitive Collections

  • Int2IntHashMap
  • Int2ObjectHashMap
  • IntHashMap
    Using Base Java Collections with generic type means any function call taking a key/value of that type will allocate since it will need to box the primitive type with the object version, which in hot path leads to MBs of garbage being generated.

ProceduralGenerator

  • tileVertexKeys & faceVertexKeys now all use preallocated arrays instead of allocating on each call
  • Combined isWaterTile & skipTile arrays int a byte[][][] tileFlags
  • Each step will presize their collections based on previous scene context if present & valid
  • Added New Step: MainTileOverridesGenerator
    • PreCalculates TileOverrides for all tiles within the scene, avoiding it being resolved multiple times
    • Uses Previous Scene Context to copy tiles which can be reused

Area

  • Added areaBounds AABB which acts as an early rejection
  • If there is more than 4 AABBs then it'll sort AABBs based on distance from the corners of the area + their size

@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 6 times, most recently from 82dcec3 to 19f993d Compare April 25, 2026 01:21
@RuffledPlume RuffledPlume changed the title Procedural generator alloc free ProcGen & Scene Static Upload Memory Optimizations Apr 25, 2026
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 13 times, most recently from fbd66a6 to cb22396 Compare May 1, 2026 21:46
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from aaaf37e to 7a1dd70 Compare May 21, 2026 17:39
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 7a1dd70 to 3e7c711 Compare May 21, 2026 20:10
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 2 times, most recently from 999c2a1 to 4e4b2df Compare May 22, 2026 02:14
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 580945a to 69ef8a0 Compare May 22, 2026 02:36
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 2 times, most recently from bd2a320 to 620b787 Compare May 22, 2026 16:44
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 620b787 to 8520453 Compare May 22, 2026 16:44
AsyncCachedModel now has a fixed count of 32, the config no longer repersents the amount of memory used since the caching uses the Pooled Arrays
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 7f52090 to a40e100 Compare May 22, 2026 22:44
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 3 times, most recently from 7f48985 to 2d530e6 Compare May 22, 2026 23:53
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 2d530e6 to b89d4b6 Compare May 22, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant